package com.renwei.yunlong.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.SwitchCompanyBean;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by wangqi on 2018/1/5.
 */

// 选择企业  adapter
public class SwitchCompanyAdapter extends BaseRecyclerViewAdapter<SwitchCompanyBean.RowsBean> {

    private String title;

    public SwitchCompanyAdapter(Context context, String title) {
        super(context);
        this.title = title;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new PopViewHolder(inflater.inflate(R.layout.item_company_title, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        SwitchCompanyBean.RowsBean item = getItem(position);
        PopViewHolder popViewHolder = (PopViewHolder) holder;
        if (item != null) {
            if (title.equals(item.getCompanyName())) {
                popViewHolder.tvTitle.setTextColor(Color.parseColor("#689DF8"));
                popViewHolder.ivCheck.setVisibility(View.VISIBLE);
            } else {
                popViewHolder.tvTitle.setTextColor(Color.parseColor("#333333"));
                popViewHolder.ivCheck.setVisibility(View.GONE);
            }
            popViewHolder.tvTitle.setText(item.getCompanyName());
        }
        popViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(v, position);
            }
        });
    }

    class PopViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_title)
        TextView tvTitle;
        @Bind(R.id.iv_check)
        ImageView ivCheck;

        public PopViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
